package com.pzb.web.controller.market;

import java.util.List;

import com.pzb.market.domain.MkGroupbuying;
import com.pzb.wechat.service.IWechatAppletService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pzb.common.annotation.Log;
import com.pzb.common.core.controller.BaseController;
import com.pzb.common.core.domain.AjaxResult;
import com.pzb.common.enums.BusinessType;
import com.pzb.market.domain.MkPanicbuying;
import com.pzb.market.service.IMkPanicbuyingService;
import com.pzb.common.utils.poi.ExcelUtil;
import com.pzb.common.core.page.TableDataInfo;

/**
 * 限时抢购Controller
 * 
 * @author Mr_Wu
 * @date 2021-12-22
 */
@RestController
@RequestMapping("/market/panicbuying")
public class MkPanicbuyingController extends BaseController
{
    @Autowired
    private IMkPanicbuyingService mkPanicbuyingService;
    @Autowired
    private IWechatAppletService wechatAppletService;

    /**
     * 查询限时抢购列表
     */
    @PreAuthorize("@ss.hasPermi('market:panicbuying:list')")
    @GetMapping("/list")
    public TableDataInfo list(MkPanicbuying mkPanicbuying)
    {
        mkPanicbuying.setExtAppid(wechatAppletService.getExtAppid());
        startPage();
        List<MkPanicbuying> list = mkPanicbuyingService.selectMkPanicbuyingList(mkPanicbuying);
        return getDataTable(list);
    }

    /**
     * 查询限时抢购列表
     */
    @PreAuthorize("@ss.hasPermi('market:panicbuying:list')")
    @GetMapping("/panicbuyList")
    public AjaxResult panicbuyList(MkPanicbuying mkPanicbuying)
    {
        mkPanicbuying.setExtAppid(wechatAppletService.getExtAppid());
        List<MkPanicbuying> list = mkPanicbuyingService.selectMkPanicbuyingList(mkPanicbuying);
        return AjaxResult.success(list);
    }

    /**
     * 获取限时抢购详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:panicbuying:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mkPanicbuyingService.selectMkPanicbuyingById(id));
    }

    /**
     * 新增限时抢购
     */
    @PreAuthorize("@ss.hasPermi('market:panicbuying:add')")
    @Log(title = "限时抢购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MkPanicbuying mkPanicbuying)
    {
        String extAppid = wechatAppletService.getExtAppid();
        if("1".equals(extAppid)){
            return AjaxResult.error("您还没有小程序!");
        }
        mkPanicbuying.setExtAppid(extAppid);
        return toAjax(mkPanicbuyingService.insertMkPanicbuying(mkPanicbuying));
    }

    /**
     * 修改限时抢购
     */
    @PreAuthorize("@ss.hasPermi('market:panicbuying:edit')")
    @Log(title = "限时抢购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MkPanicbuying mkPanicbuying)
    {
        return toAjax(mkPanicbuyingService.updateMkPanicbuying(mkPanicbuying));
    }
    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('market:panicbuying:edit')")
    @Log(title = "限时抢购", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody MkPanicbuying mkPanicbuying)
    {
        return toAjax(mkPanicbuyingService.updateMkPanicbuying(mkPanicbuying));
    }

    /**
     * 删除限时抢购
     */
    @PreAuthorize("@ss.hasPermi('market:panicbuying:remove')")
    @Log(title = "限时抢购", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mkPanicbuyingService.deleteMkPanicbuyingByIds(ids));
    }
}
